﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace ArmaTuCumple.Model.Repository
{
    class RepositorioFinal<T>:IRepositorioFinal<T> where T:class
    {

        readonly ArmaTuCumple.Model.Repository.ArmaTuCumpleLinqDataContext dataContext;

            public RepositorioFinal()
             {
                 dataContext = new ArmaTuCumpleLinqDataContext();
             }


        public IEnumerable<T> All()
        {
            return dataContext.GetTable<T>();
        }

        public IEnumerable<T> FindAll(Func<T, bool> exp)
        {
            return dataContext.GetTable<T>().Where<T>(exp);
        }

        public T Single(Func<T, bool> exp)
        {
            return dataContext.GetTable<T>().Single(exp);
        }

        public T First(Func<T, bool> exp)
        {
            return dataContext.GetTable<T>().First(exp);
        }

        public void DeleteOnSubmit(T entity)
        {
            dataContext.GetTable<T>().DeleteOnSubmit(entity);
        }

        public void SubmitChanges()
        {
            dataContext.SubmitChanges();
        }


        public void InsertOnSubmit(T entity)
        {
            dataContext.GetTable<T>().InsertOnSubmit(entity);
        }
    }
}
